<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <title>收益支付</title>
<!--    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <script src="../lib/layuimini/lib/layui-v2.5.5/layui.js"></script>
    <script src="../lib/layuimini/js/lay-config.js"></script>-->
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css"/>

    <script type="text/javascript">
        var layid =11;

        layui.use(['element', 'form', 'table', 'layer', 'laydate'], function () {
            var layer = layui.layer;
            var $ = layui.$;
            var table = layui.table;
            var form = layui.form;
            var formSelects = layui.formSelects;
            var laydate = layui.laydate;
            var fundId=$("#fundId").val();
            //执行一个laydate实例
            laydate.render({
                elem: '#statDate' //指定元素

            });

            table.render({
                elem: '#dong1',
                url:'cashInterestIncome',
                page: true,
                height:'full-50',
                cellMinWidth: 50,
                cols:[
                    [
                        {type: 'checkbox', fixed: 'left'}
                        , {field: 'cashInventoryTime', title: '业务时间'}
                        , {field: 'accounName', title: '账户名称'}
                        , {field: 'businessType', title: '业务类型',templet: function(item){
                            if (item.businessType==1){
                                return '管理费'
                            }else if (item.businessType==2){
                                return '托管费'
                            }else if (item.businessType==3){
                                return '存款利息'
                            }else if (item.businessType==4){
                                return '申购赎回款'
                            }
                        }}
                        , {field: 'businessStatu', title: '流入流出',templet:function (item){
                            if (item.businessStatu == 1){
                                return '流入'
                            }else{
                                return '流出'
                            }
                        }
                    }
                        , {field: 'cashTotalAmount', title: '收支金额'}

                    ]
                ]
            });
            //债券利息
            table.render({
                elem:'#dong2' ,
                url: 'BondInterestIncome',
                page: true,
                height:'full-50',
                cellMinWidth: 50,
                cols:[
                    [
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'securityInventoryTime', title: '业务时间', align:'center'}
                        ,{field: 'securityName', title: '证券名称', align:'center'}
                        ,{field: 'securityType', title: '业务类型', align:'center',templet:function (item){
                            if (item.securityType == 1){
                                return '估值增值'
                            }else if (item.securityType == 2){
                                return '债卷清算款'
                            }else if (item.securityType == 3){
                                return '债卷利息'
                            }}
                    }
                        ,{field: 'businessStatu', title: '流入流出', align:'center',templet:function (item){
                            if (item.businessStatu == 1){
                                return '流入'
                            }else{
                                return '流出'
                            }}
                    }
                        ,{field: 'securityTotalAmount', title: '收支金额',align:'center'}
                    ]
                ]
            });
            table.render({
                elem: '#dong3',
                url: 'payTwoFees',
                page: true,
                height: 'full',
                minLength:80,
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'}
                        // ,{field: 'fundName', title: '基金名称',align:'center'}
                        ,{field: 'cashInventoryTime', title: '业务时间', align:'center'}
                        ,{field: 'accounName', title: '账号名称',  align:'center'}
                        ,{field: 'businessType', title: '业务类型',  align:'center',templet:function (item){
                            if (item.businessType == 1){
                                return '管理费'
                            }else if (item.businessType == 2){
                                return '托管费'
                            }else {
                                return '未知'
                            }}}
                        ,{field: 'cashTotalAmount', title: '金额',  align:'center'}
                        ,{field: 'businessStatu', title: '流入流出',  align:'center',templet:function (item){
                            if (item.businessStatu == 1){
                                return '流入'
                            }else{
                                return '流出'
                            }}
                    }
                    ]
                ]
            });
            form.on('submit(searchSubmit)', function (data) {
                console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                console.log(data.field.statDate);
                if(layid==11){
                    table.reload('dong1', {
                            url:'cashInterestIncome',
                            where: {
                                date:$("#statDate").val(),
                            },
                            page: {
                                curr: 1
                            }
                        }
                    );
                }else if (layid==22){
                    table.reload('dong2', {
                            url:'BondInterestIncome',
                            where: {
                                date:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }else{
                    table.reload('dong3', {
                            url:'payTwoFees',
                            where: {
                                date:$("#statDate").val(),
                            }
                            , page: {
                                curr: 1
                            }
                        }
                    );
                }


                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

            });

            table.on('toolbar(userTable)', function(obj){
                var data = obj.data;
                if(obj.event==='tongJi'){
                    layer.msg('开始统计');
                }
            });

            form.on('submit(tongJi)', function (data) {
                //console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
                //console.log(data.field.statDate);

                if(layid==11){
                    var checkStatus = table.checkStatus("dong1"); // 获得选中行所有数据
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var cashs = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        cashs.push(n);
                    });
                    // alert(cashs);
                    var cash = JSON.stringify(cashs);


                    // layer.close();
                    //向服务端发送删除指令
                    $.post("insertIncomePaymentIncome", "cash="+cash,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }else if(layid==22){
                    var checkStatus = table.checkStatus("dong2"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var Securitie = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        Securitie.push(n);
                    });
                    var Securities = JSON.stringify(Securitie);
                    var accountIds=$("#accountIds").val();
                    // layer.close();
                    //向服务端发送删除指令
                    $.post("insertDataBondInterestIncome", {Securities:Securities ,accountIds:accountIds},function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }else{
                    var checkStatus = table.checkStatus("dong3"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var TwoFee = [];
                    var dataArr = checkStatus.data; //获取选中行的数据
                    $.each(dataArr, function (i, n) {
                        TwoFee.push(n);
                    });
                    // alert(cashs);
                    var TwoFees = JSON.stringify(TwoFee);


                    // layer.close();
                    //向服务端发送删除指令
                    $.post("payTwoFee", "TwoFees="+TwoFees,function(msg){
                        if(msg>0){
                            table.reload('myTable');
                            layer.closeAll();
                            layer.msg('统计成功',{
                                title : '提示',
                                area : [ '200px',
                                    '140px' ],
                                time : 0,
                                btn : [ '知道了' ]
                            });
                        }
                    });
                }

            });
        });

    </script>
</head>
<body>

<div style=" margin-top: 20px;margin-left: 10px">
    <form id="searchDate" class="layui-form layui-col-space5">
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">业务日期</label>

            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" autocomplete="off" placeholder="请输入统计日期" name="statDate" id="statDate">
                <input name="fundId" type="hidden" id="fundId">
                <input name="accountIds" type="hidden"  id="accountIds">
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="searchSubmit" ><i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" lay-submit="" type="button" lay-event="tongJi" lay-filter="tongJi" ><i class="layui-icon layui-icon-table"></i>统计
            </button>

        </div>
    </form>
</div>

<div class="layui-tab" lay-filter="test1">
    <ul class="layui-tab-title" style="border-bottom-color: dodgerblue; color: dodgerblue">
        <li class="layui-this" lay-id="11" >现金利息收入</li>
        <li lay-id="22" >债券利息收入</li>
        <li lay-id="33" >支付两费</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <!--表格-->
            <table id="dong1" lay-filter="dong1"></table>
        </div>
        <div class="layui-tab-item">
            <table id="dong2" lay-filter="dong2"></table>
        </div>
        <div class="layui-tab-item">
            <table id="dong3" lay-filter="dong3"></table>
        </div>
    </div>
</div>
<script>
    layui.use('element', function(){
        var element = layui.element;


        //监听Tab切换，以改变地址hash值
        element.on('tab(test1)', function(){
            location.hash = 'test1='+ this.getAttribute('lay-id');

        });
        element.on('tab(test1)', function () {
            layid = this.getAttribute('lay-id');


        });
    });
</script>
</body>
</html>